package pl.minim.unidefCMS.objects {

	/**
	 * @author Marek Brun
	 */
	public class UnidefNumber extends AbstractUnidefObject {
		
		static public const TYPE_NUMBER:String="number";		static public const TYPE_INT:String="int";		public var value:Number=0;
		public var min:Number;
		public var max:Number;		public var type:String;
		
		public function UnidefNumber() {
			
		}
		
		public function repairNumber(num:Number):Number {
			dbg.log('!isNaN(max):'+(!isNaN(max)));
			if(type==TYPE_INT){ num=int(num); }
			if(!isNaN(min) && num<min){ num=min; }
			if(!isNaN(max) && num>max){ num=max; }
			return num;
		}
		
		override public function getTypeName():String {
			return 'Number';
		}
		
		override public function getDataAsTextPreview():String {
			return String(value);
		}
		
		override public function toXML():XML {
			var xml:XML=<i/>;
			xml.appendChild(value);
			return xml;
		}
		
		override public function exportToRawData():* {
			return value;
		}
		
	}
}
